package a07_二叉树;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * a01_二叉树的前序遍历
 * </p>
 *
 * @author flyduck
 * @since 2024-08-19
 */
public class a02_二叉树的递归遍历复习0 {

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(1, null, new TreeNode(2, new TreeNode(3, null, null), null));
        List<Integer> result = new ArrayList<>();
        preorderTraversal(treeNode,result);
        System.out.println(result);

    }

    //前序 中左右
    public static void preorderTraversal(TreeNode root,List<Integer> result) {
        if (root == null) {
            return;
        }
        result.add(root.val);
        preorderTraversal(root.left, result);
        preorderTraversal(root.right, result);
    }

    //中序 左中右
    public static void inorderTraversal(TreeNode root,List<Integer> result) {
        if (root == null) {
            return;
        }
        inorderTraversal(root.left, result);
        result.add(root.val);
        inorderTraversal(root.right, result);
    }

    //后序 左右中
    public static void postorderTraversal(TreeNode root,List<Integer> result) {
        if (root == null) {
            return;
        }
        postorderTraversal(root.left, result);
        postorderTraversal(root.right, result);
        result.add(root.val);
    }




}
